package com.chapter01exercise.homework08;

/**
 * @Author 小闽
 * @Date 2024/8/17 10:59
 * @PackageName: com.chapter01exercise.homework08
 * @ClassName: savingsAccount
 * @Description: 利息类
 * @Version 1.0
 */
public class SavingsAccount extends BankAccount {
    private int count = 3;
    private double rate = 0.01;

    /**
     * 构造器
     * @param initialBalance
     */
    public SavingsAccount(int initialBalance) {
        super(initialBalance);
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public double getRate() {
        return rate;
    }

    public void setRate(double rate) {
        this.rate = rate;
    }

    /**
     * 重写父类的存款方法
     * @param amount
     */
    @Override
    public void deposit(double amount) {
        if (getCount() > 0){
            super.deposit(amount);
        }else{
            super.deposit(amount -1);
        }
        count--;
    }
    /**
     * 重写父类的取款方法
     */
    @Override
    public void withdraw(double amount) {
        if (getCount() > 0){
            super.withdraw(amount);
        }else{
            super.withdraw(amount + 1);
        }
        count--;
    }
    /**
     * 重置交易计数的方法
     */
    public void earnMonthlyInterest(){
        count = 3;
        super.deposit(getBalance() * getRate());
    }
}
